package cdu.sl.controller;

import cdu.sl.pojo.OperateLog;
import cdu.sl.pojo.PageResult;
import cdu.sl.pojo.Result;
import cdu.sl.service.LogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LogController {
    private static final Logger log = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private LogService logService;

    /**
     * 日志信息分页查询
     *
     * @return
     */
    @GetMapping("/log/page")
    public Result getLogList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("日志信息分页查询,page:{},pageSize:{}", page, pageSize);
        // 1. 设置分页参数
        PageHelper.startPage(page, pageSize);
        // 2.获取查询到的结果
        List<OperateLog> logList = logService.getLogList();
        Page<OperateLog> p = (Page<OperateLog>) logList;

        return Result.success(new PageResult<>(p.getTotal(),p.getResult()));
    }

}
